package br.com.tonaaula;

import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.content.res.Configuration;
import android.util.Log;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class MainActivity extends ListActivity {

	//comentario Fabio
	public static List<String> disciplinas = new ArrayList<String>();
	private DatabaseHelper helper;

	
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		helper = new DatabaseHelper(this);
		

		registerForContextMenu(getListView());
	}
	
	@Override
	protected void onResume() {
		((BaseAdapter) this.getListAdapter()).notifyDataSetChanged();
		//this.getListView().invalidateViews();
		DisciplinaDAO dao = new DisciplinaDAO(helper);
		
		String[] from = {"imagem","data","hora","valor"};
		int[] to = {R.id.imagem,R.id.data,R.id.hora,R.id.valor};
		
		//SimpleAdapter adapter = new SimpleAdapter(this, dao.listar(), R.layout.item, from, to);
		//this.setListAdapter(adapter);
		super.onResume();
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		String item = (String) this.getListAdapter().getItem(position);
		Toast.makeText(this, item, Toast.LENGTH_LONG).show();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// // Inflate the menu; this adds items to the action bar if it is
		// present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.add_disciplina) {
			Intent add = new Intent(this, AddDisciplinaActivity.class);
			startActivity(add);
		}else if(item.getItemId() == R.id.action_settings){
			Intent add = new Intent(this, ConfigActivity.class);
			startActivity(add);
		}
		return super.onOptionsItemSelected(item);
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View v,
			ContextMenuInfo menuInfo) {
		getMenuInflater().inflate(R.menu.context_disciplina, menu);
		super.onCreateContextMenu(menu, v, menuInfo);
	}

	@Override
	public boolean onContextItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.detalhes:
			Toast.makeText(this, item.getTitle(), Toast.LENGTH_LONG).show();
			break;
		case R.id.exluir:
			Toast.makeText(this, item.getTitle(), Toast.LENGTH_LONG).show();
			break;
		case R.id.to_aqui:
			Toast.makeText(this, item.getTitle(), Toast.LENGTH_LONG).show();
			break;

		default:
			break;
		}

		return super.onContextItemSelected(item);
	}

}
